<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('热表采集数据')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 热表信息
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>热表id：</label>

                                <input type="text" id="calorimeterId" name="calorimeterId" th:value="${calorimeterId}"/>
                            </li>
                            <li class="select-time">
                                <label>查询时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]" th:value="${beginTime}"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]" th:value="${endTime}"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="getData()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <div class="col-sm-12" id="calor" style="height:400px;border:1px solid lightgrey;background:#e5e3dc;">
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: echarts-js" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var prefix = ctx + "report/calor";

    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        queryCalorimeterTree();
    });

    function queryCalorimeterTree()
    {
        var url = ctx + "module/calorimeter/data/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#calorimeterId").val(treeNode.id);
            getCalor();
        }
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function() {
        queryCalorimeterTree();
    });

    function getData(){
        var calorimeterId = $("#calorimeterId").val();
        if(calorimeterId==''){
            alert("请选择一个热表");
            return;
        }
        getCalor();
    }

    function getCalor(){
        var barChart = echarts.init(document.getElementById('calor'));
        var names=[];
        var inlets=[];
        var outlets=[];
        barChart.showLoading();//加载动画

        $.ajax({
            url: prefix + '/valveSummary',
            async: true,
            type: "POST",
            dataType: "json",
            data: $("#formId").serializeArray(),
            success: function (json) {
                for (var i = 0; i < json.data.length; i++) {
                    names.push(json.data[i].createTime);
                    inlets.push(json.data[i].inlet);
                    outlets.push(json.data[i].outlet);
                }
                barChart.hideLoading();//隐藏加载动画
                barChart.setOption({
                    title: {
                        text: '热量图'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['进水温度', '回水温度']
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            dataView: {show: true, readOnly: false},
                            magicType: {show: true, type: ['line', 'bar']},
                            restore: {show: true},
                            saveAsImage: {show: true}
                        }
                    },
                    calculable: true,
                    xAxis: {
                        type: 'category',
                        data: names
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '进水温度',
                        type: 'bar',
                        data: inlets,
                        markPoint: {
                            data: [
                                {type: 'max', name: '最大进水温度'},
                                {type: 'min', name: '最小进水温度'}
                            ]
                        },
                        markLine: {
                            data: [
                                {type: 'average', name: '平均进水温度'}
                            ]
                        }
                    },{
                        name: '回水温度',
                        type: 'bar',
                        data: outlets,
                        markPoint: {
                            data: [
                                {type: 'max', name: '最大回水温度'},
                                {type: 'min', name: '最小回水温度'}
                            ]
                        },
                        markLine: {
                            data: [
                                {type: 'average', name: '平均回水温度'}
                            ]
                        }
                    }]
                });
            }
        });
    }
</script>
</body>